package cn.itcast.mq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Direc 通过routingkey判断由交换机将数据给对应的队列
 */
@Component
public class ConsumerDirectAmqpTest {

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(name = "exchange.direct",type = ExchangeTypes.DIRECT),
            value = @Queue(name = "simple.queue1"),
            key = {"red","orange"} //routingkey 交换机通过指定的路由key选择拥有相同key的队列
    ))
    public void ConsumerDirectAmqpTest(String msg) {
        System.out.println("1号消费"+msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "simple.queue2"),
            exchange = @Exchange(name = "exchange.direct",type = ExchangeTypes.DIRECT),
            key = {"pink,red"}
    ))
    public void ConsumerDirectAmqp2Test(String msg) {
        System.out.println("2号消费"+msg);
    }
}
